package com.li.cms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.li.cms.entity.CrmBanner;
import com.li.cms.service.CrmBannerService;
import com.li.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *     后台banner管理接口
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-04-09
 */
@RestController
@RequestMapping("/educms/banneradmin")
//@CrossOrigin
public class CrmAdminController {

    @Autowired
    private CrmBannerService bannerService;
    //分页查询banner
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable Long page,@PathVariable Long limit){

        Page<CrmBanner> pageBanner = new Page<>(page,limit);
        bannerService.page(pageBanner,null);

        return R.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }


    //添加banner
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }

    //修改banner
    @PutMapping("update")
    public R updateBanner(@RequestBody CrmBanner banner){
        bannerService.updateById(banner);
        return R.ok();
    }

    //删除banner
    @DeleteMapping("delete/{id}")
    public R deleteBanner(@PathVariable String id){
        bannerService.removeById(id);
        return R.ok();
    }

    //根据Id查询
    @GetMapping("get/{id}")
    public R getBanner(@PathVariable String id){
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item",banner);
    }
}

